package observer;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zhangxi
 * @date 2020/9/23
 */
public class WeatherData implements Subject {

    List<Observer> list;

    public WeatherData() {
        list = new ArrayList();
    }

    private float temp;
    private float pressuer;


    public void regist(Observer observer) {
        list.add(observer);
    }

    public void removeObserver(Observer observer) {
        int i = list.indexOf(observer);
        list.remove(i);
    }

    public void notifyOberver() {
        for (Observer observer : list) {
            observer.update(temp, pressuer);
        }
    }

    public void messageChange() {
        notifyOberver();
    }

    public void setMessage(float temp, float pressuer) {
        this.pressuer = pressuer;
        this.temp = temp;
        messageChange();
    }
}
